package client.comm.baoding.ui.me

import android.view.View
import androidx.lifecycle.Observer
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.R
import client.comm.baoding.api.event.EventUserInfo
import client.comm.baoding.databinding.ActivityRealnameVerifyBinding
import client.comm.baoding.ui.vm.RegisterViewModel
import client.comm.commlib.dialog.CameraOrSelectDialog
import client.comm.commlib.toast.toast
import org.greenrobot.eventbus.EventBus

class RealNameVerifyActivity :
    BaseMiddleActivity<RegisterViewModel, ActivityRealnameVerifyBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_realname_verify
    }

    override fun initViewModel(): RegisterViewModel = createViewModel()

    override fun initView() {
        binding?.apply {
            login = this@RealNameVerifyActivity
            vm = viewModel

        }
    }

    override fun observerUI() {
        viewModel.realNameVerifyRet.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast(it.message)//实名成功
                    EventBus.getDefault().post(EventUserInfo())
                    finish()
                } else {
                    toast(it.message)
                }
            }
        })
    }

    fun imgSelect() {
        CameraOrSelectDialog(this).apply {
            suc = {
                viewModel.imgOne.value = it

                this@RealNameVerifyActivity.binding.fontTv.visibility = View.GONE
                this@RealNameVerifyActivity.binding.idFontImg.visibility = View.VISIBLE
                mImgLoader.load(it).into(this@RealNameVerifyActivity.binding.idFontImg)
            }
        }.show()
    }


}